/*
 * This file is part of quickReminder, a software for gamers
 *
 * Copyright (C) 2006-2008 Lucas Romero
 *
 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/>.
 */
using System;
using System.Windows.Forms;
using LucasCode.Tools;
using LucasCode.PublicTypes;
using System.IO;
using XPTable.Models;

namespace LucasCode
{
    public partial class FormArchiveBrowser : Form
    {
        public FormArchiveBrowser()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (folderbrowse.ShowDialog() == DialogResult.OK)
            {
                tbPath.Text = folderbrowse.SelectedPath;
                ScanDir(tbPath.Text);
            }
        }

        private void ScanDir(string path)
        {
            tableModel1.Rows.Clear();
            DirectoryInfo d = new DirectoryInfo(path);
            foreach (FileInfo f in d.GetFiles("*.qma"))
            {
                MatchArchive a = FileSerializer.loadMatchArchiveFromQmaFile(f.FullName);
                if (a == null)
                    continue;
                Row r = new Row();
                r.Cells.Add(new Cell(f.Name));
                r.Cells.Add(new Cell(f.Length.ToString()));
                r.Cells.Add(new Cell(a.Files.Length.ToString()));
                r.Cells.Add(new Cell(a.DateCreated.ToString()));
                Cell c = new Cell(Enum.GetName(typeof(MatchStatus), a.Status));
                //c.Text = Enum.GetName(typeof(MatchStatus), a.Status);
                r.Cells.Add(c);
                tableModel1.Rows.Add(r);
            }
        }
    }
}